home *** CD-ROM | disk | FTP | other *** search
Wrap
/*************************************************************** * MICROCHECK ST * * by Clayton Walnum * * * * Copyright 1989 by ST-LOG * * Developed with Laser C * * * * Maintenance history: * * 7/13/89 -- Fixed divide-by-zero error in calc_vslid(). * * 9/13/89 -- Deleted obsolete "mnth" code from open_acct(). * * Changed read in open_acct() to read only 16 * * bytes into CHKCITY field, rather than 26. * ***************************************************************/ #include <stdio.h> #include <osbind.h> #include <gemdefs.h> #include <obdefs.h> #include <fcntl.h> #include "microchk.h" #define WA_UPPAGE 0 #define WA_DNPAGE 1 #define WA_UPLINE 2 #define WA_DNLINE 3 #define WA_LFPAGE 4 #define WA_RTPAGE 5 #define BOLD 1 #define LIGHT 2 #define TRUE 1 #define FALSE 0 #define YES 1 #define NO 2 #define LEFT_BUTTON 0x0001 #define BUTTON_DOWN 0x0001 #define NUM_CLICKS 2 #define PARTS NAME|INFO|UPARROW|DNARROW|VSLIDE|FULLER|CLOSER|HSLIDE #define NUM_COLUMNS 93 #define MED 1 #define MATCH 0 #define REC_LENGTH 117 #define FROM_BEG 0 #define FROM_CUR_POS 1 #define FAILED (-1) #define DFLT_DRV 0 #define VISIBLE 1 #define MEDIUM 1 #define HIGH 2 #define CHAR_AVAIL -1 #define CONSOLE 2 #define ESCAPE 27 #define CNTL_A 0x1e01 #define CNTL_B 0x3002 #define CNTL_C 0x2e03 #define CNTL_D 0x2004 #define CNTL_E 0x1205 #define CNTL_G 0x2207 #define CNTL_I 0x1709 #define CNTL_M 0x320d #define CNTL_N 0x310e #define CNTL_O 0x180f #define CNTL_P 0x1910 #define CNTL_Q 0x1011 #define CNTL_R 0x1312 #define CNTL_S 0x1f13 #define CNTL_W 0x1117 #define CNTL_Y 0x1519 int work_in[11], work_out[57], contrl[12], intin[128], ptsin[128], intout[128], ptsout[128]; int msg_buf[8]; long pwrs[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 }; int handle, dum, file, key, fullx, fully, fullw, fullh, wrkx, wrky, wrkw, wrkh, w_h1, w_h2, res, full, num_trans, charw, charh, curchknum, num_deps, num_chks, loaded, all_done, mouse_x, mouse_y, num_clicks, edit_top, left, start_mnth, end_mnth, mnth, srch_trans, start_num, end_num, cur_count, cur_top, search, saved, canceling, month, full_draw, oldcolr; int zero = 0; char filename[64], chkname[30], chkstreet[30], chkcity[50], date_but[10], bal_but[10], trans_but[4], check_but[4], dep_but[4], mnth_but[10], acct_name[64], monthfile[64], cur_chk_num[6], cur_date[7], future_use[40], cancmnth[5], chtot[20], dptot[20], chcnt[10], dpcnt[10]; char windname[64]; char noacct[] = "No account opened"; char canc[] = "CANCEL CHECKS"; char newm[] = " NEW MONTH "; char *months[] = { "Month 0", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; char spaces[] = " "; char infotext[] = " Number Amount Payee Memo Date"; char *string, *srch_payee, *srch_memo; char rule[] = "------------------------------------------------------------------------------"; long balance, start_amnt, end_amnt; OBJECT *menu_addr, *check_addr, *newacct_addr, *newfile_addr, *newdate_addr, *srchdial_addr, *cancdial_addr, *recndial_addr, *rprtdial_addr, *lkmndial_addr, *srtodial_addr; FILE *acctfile, *mfile; char *get_tedinfo_str (); FILE *opn_nw_auto (); long str_to_long (); struct check { char number[5]; char payee[31]; char memo[31]; char date[9]; long amount; char cancel[2]; }; struct check checks[500]; struct check srch_checks[1000]; struct check *cur_chk_strc; TEDINFO *ob_tedinfo; main () { appl_init (); /* Initialize application. */ open_vwork (); /* Set up workstation. */ do_mcheck(); /* Go do MicroCheck. */ v_clsvwk (handle); /* Close virtual workstation. */ Setcolor ( 2, oldcolr ); /* Reset color register. */ appl_exit (); /* Back to the desktop. */ } do_mcheck() { oldcolr = Setcolor ( 2, -1 ); Setcolor ( 2, 0x005 ); if ( (res = Getrez ()) != HIGH && res != MEDIUM ) form_alert(1,"[0][MicroCheck ST runs|only in high or medium |resolution.][OK]"); else { graf_mouse ( ARROW, &dum ); strcpy ( acct_name, "NONE" ); strcpy ( cur_chk_num, "0000" ); balance = 0; month = -1; edit_top = cur_top = num_trans = num_chks = num_deps = 0; left = saved = TRUE; search = canceling = full_draw = FALSE; cur_chk_strc = checks; get_date (); if ( !rsrc_load ( "\MICROCHK.RSC" ) ) form_alert ( 1, "[1][MICROCHK.RSC missing!][Okay]" ); else { rsrc_gaddr ( R_TREE, MENUBAR, &menu_addr ); rsrc_gaddr ( R_TREE, CHEKDIAL, &check_addr ); rsrc_gaddr ( R_TREE, NEWADIAL, &newacct_addr ); rsrc_gaddr ( R_TREE, FILEDIAL, &newfile_addr ); rsrc_gaddr ( R_TREE, DATEDIAL, &newdate_addr ); rsrc_gaddr ( R_TREE, SRCHDIAL, &srchdial_addr ); rsrc_gaddr ( R_TREE, CANCDIAL, &cancdial_addr ); rsrc_gaddr ( R_TREE, RECNDIAL, &recndial_addr ); rsrc_gaddr ( R_TREE, RPRTDIAL, &rprtdial_addr ); rsrc_gaddr ( R_TREE, LKMNDIAL, &lkmndial_addr ); rsrc_gaddr ( R_TREE, SRTODIAL, &srtodial_addr ); menu_bar ( menu_addr, TRUE ); set_menu_entries (); wind_get ( 0, WF_WORKXYWH, &fullx, &fully, &fullw, &fullh ); w_h1 = wind_create ( 0, fullx, fully, fullw, fullh ); w_h2 = wind_create ( PARTS, fullx, fully, fullw, fullh ); wind_set ( w_h2, WF_NAME, noacct, 0, 0 ); wind_set ( w_h2, WF_INFO, infotext, 0, 0 ); wind_open ( w_h1, fullx, fully, fullw, fullh ); wind_open ( w_h2, fullx, fully, fullw, 316 - 162*(res==MED) ); calc_vslid ( 1 ); calc_hslid ( NUM_COLUMNS ); full = FALSE; loaded = FALSE; get_event (); menu_bar ( menu_addr, FALSE ); wind_close ( w_h2 ); wind_delete ( w_h2 ); wind_close ( w_h1 ); wind_delete ( w_h1 ); rsrc_free (); } } } get_event () { int h, event; all_done = FALSE; while ( !all_done ) { event = evnt_multi ( MU_KEYBD|MU_MESAG|MU_BUTTON, NUM_CLICKS, LEFT_BUTTON, BUTTON_DOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, msg_buf, 0, 0, &mouse_x, &mouse_y, &dum, &dum, &key, &num_clicks ); if ( event & MU_KEYBD ) handle_keys (); if ( event & MU_MESAG ) handle_messages (); if ( event & MU_BUTTON ) handle_button (); } } handle_keys () { int button; if ( loaded && !search && !canceling ) switch ( key ) { case CNTL_A: menu_tnormal ( menu_addr, CHECKS, FALSE ); do_auto (); menu_tnormal ( menu_addr, CHECKS, TRUE ); break; case CNTL_E: menu_tnormal ( menu_addr, CHECKS, FALSE ); do_enter (); menu_tnormal ( menu_addr, CHECKS, TRUE ); break; case CNTL_M: menu_tnormal ( menu_addr, FILEBAR, FALSE ); do_new_mnth (); menu_tnormal ( menu_addr, FILEBAR, TRUE ); break; case CNTL_P: menu_tnormal ( menu_addr, CHECKS, FALSE ); do_check_canc (); menu_tnormal ( menu_addr, CHECKS, TRUE ); break; case CNTL_R: menu_tnormal ( menu_addr, CHECKS, FALSE ); do_reconcil (); menu_tnormal ( menu_addr, CHECKS, TRUE ); break; } if ( !loaded ) switch ( key ) { case CNTL_N: menu_tnormal ( menu_addr, FILEBAR, FALSE ); do_newacct (); menu_tnormal ( menu_addr, FILEBAR, TRUE ); break; case CNTL_O: menu_tnormal ( menu_addr, FILEBAR, FALSE ); button = get_acct (); if ( button ) open_acct ( filename ); menu_tnormal ( menu_addr, FILEBAR, TRUE ); break; case CNTL_Y: menu_tnormal ( menu_addr, UTILITY, FALSE ); do_new_year (); menu_tnormal ( menu_addr, UTILITY, TRUE ); break; case CNTL_I: menu_tnormal ( menu_addr, UTILITY, FALSE ); do_import (); menu_tnormal ( menu_addr, UTILITY, TRUE ); break; } switch ( key ) { case CNTL_Q: menu_tnormal ( menu_addr, FILEBAR, FALSE ); do_quit (); menu_tnormal ( menu_addr, FILEBAR, TRUE ); break; case CNTL_S: if ( loaded && !canceling ) { menu_tnormal ( menu_addr, CHECKS, FALSE ); do_search (); menu_tnormal ( menu_addr, CHECKS, TRUE ); } break; case CNTL_C: if ( loaded ) { menu_tnormal ( menu_addr, FILEBAR, FALSE ); do_wind_close (); menu_tnormal ( menu_addr, FILEBAR, TRUE ); } break; case CNTL_D: menu_tnormal ( menu_addr, UTILITY, FALSE ); get_new_date (); menu_tnormal ( menu_addr, UTILITY, TRUE ); break; case CNTL_W: if ( loaded ) { menu_tnormal ( menu_addr, PRINT, FALSE ); print_wind (); menu_tnormal ( menu_addr, PRINT, TRUE ); } break; case CNTL_G: if ( loaded ) { menu_tnormal ( menu_addr, PRINT, FALSE ); print_reg (); menu_tnormal ( menu_addr, PRINT, TRUE ); } break; } } handle_messages () { switch ( msg_buf[0] ) { case MN_SELECTED: do_menu (); break; case WM_REDRAW: do_redraw ( (GRECT *) &msg_buf[4] ); break; case WM_FULLED: do_full (); break; case WM_ARROWED: do_arrow (); break; case WM_VSLID: do_vslide (); break; case WM_HSLID: do_hslide (); break; case WM_CLOSED: do_wind_close (); break; } } do_menu () { int button; switch ( msg_buf[3] ) { case DESK: form_alert(1,"[0][ MicroCheck ST| by Clayton Walnum| (9/13/89)| |Copyright 1989 by ST-Log ][CONTINUE]"); break; case FILEBAR: switch ( msg_buf[4] ) { case NEWACCNT: do_newacct (); break; case OPENMBR: button = get_acct (); if ( button ) open_acct ( filename ); break; case CLOSEMBR: do_wind_close (); break; case NEWMNTH: do_new_mnth (); break; case QUIT: do_quit (); break; } break; case CHECKS: switch ( msg_buf[4] ) { case ENTER: do_enter (); break; case SEARCH: do_search (); break; case CHKCAN: do_check_canc (); break; case RECONCIL: do_reconcil (); break; case CHKAUTO: do_auto (); break; } break; case PRINT: switch ( msg_buf[4] ) { case PRNTWIND: print_wind (); break; case PRNTREG: print_reg (); break; } case UTILITY: switch ( msg_buf[4] ) { case NEWYEAR: do_new_year (); break; case NEWDATE: get_new_date (); break; case IMPORT: do_import (); break; } break; } menu_tnormal ( menu_addr, msg_buf[3], TRUE ); } do_new_mnth () { int choice; cancdial_addr[CANCSTRG].ob_spec = newm; choice = get_month (); if ( choice == CANCOK ) { if ( !saved ) save_month ( monthfile ); open_new_month (); } } do_wind_close () { int button; GRECT r; wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); wind_update ( BEG_UPDATE ); if ( search ) { search = FALSE; cur_top = edit_top; cur_count = num_trans; cur_chk_strc = checks; srch_trans = 0; set_menu_entries (); strcpy ( windname, acct_name ); strcpy ( &windname[strlen(windname)], ": Edit mode" ); wind_set ( w_h2, WF_NAME, windname, 0, 0 ); draw_interior ( r ); } else if ( canceling ) { if ( !saved ) save_month ( monthfile ); canceling = FALSE; strcpy ( windname, acct_name ); strcpy ( &windname[strlen(windname)], ": Edit mode" ); wind_set ( w_h2, WF_NAME, windname, 0, 0 ); draw_interior ( r ); set_menu_entries (); } else if ( loaded ) { button = form_alert ( 1, "[2][Do you want to close|this account?][YES|NO]"); if ( button == YES ) { do_save (); draw_rec ( r, 2, 8, WHITE ); set_menu_entries (); wind_set ( w_h2, WF_NAME, noacct, 0, 0 ); } } wind_update ( END_UPDATE ); } handle_button () { wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh ); if ( mouse_y > wrky && mouse_y < wrky + cur_count * charh + 4 && mouse_y < wrky + wrkh && mouse_x > wrkx && mouse_x < wrkx+wrkw && num_clicks == 1 ) if ( !search && !canceling ) edit (); else if ( canceling ) canc_chk (); } canc_chk () { int line, index; graf_mouse ( M_OFF, 0L ); line = ( mouse_y - wrky - 4 ) / charh; index = cur_top + line; if ( strcmp ( checks[index].cancel, "*" ) == MATCH ) strcpy ( checks[index].cancel, " " ); else strcpy ( checks[index].cancel, "*" ); prnt_chk_wnd ( index, wrky + charh + line * charh ); saved = FALSE; graf_mouse ( M_ON, 0L ); } do_save () { char a[20]; int len; if ( !saved ) { save_month ( monthfile ); clear_window (); } if ( ( mfile = fopen ( filename, "br+" )) == NULL ) form_alert ( 1, "[1][Error opening .MCK file!|Cannot update balance.][OK]" ); else { fseek ( mfile, 91L, FROM_BEG ); fwrite ( &balance, 4, 1, mfile ); if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); } if ( !search ) { loaded = FALSE; num_trans = num_chks = num_deps = cur_count = 0; balance = 0; month = -1; strcpy ( acct_name, "NONE" ); if ( !full ) draw_buttons (); set_menu_entries (); } } save_month ( file ) char *file; { char newmfile[64]; int x; strcpy ( newmfile, file ); strcpy ( &newmfile[strlen(newmfile)-3], "BAK" ); Fdelete ( newmfile ); if ( Frename ( 0, file, newmfile ) == FAILED ) form_alert ( 1, "[1][Error creating .BAK file!][OK]" ); if ( ( mfile = fopen ( file, "bw" )) == 0 ) { form_alert ( 1, "[1][Disk Error!|Cannot save file.][CONTINUE]" ); Frename ( 0, newmfile, file ); } else { fwrite ( &num_trans, 2, 1, mfile ); for ( x=0; x<num_trans; ++x ) save_check ( x, mfile ); if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OKAY]"); else saved = TRUE; if ( ( mfile = fopen ( filename, "br+" )) == NULL ) form_alert ( 1, "[1][Error opening .MCK file!|Cannot update balance.][OK]" ); else { fseek ( mfile, 91L, FROM_BEG ); fwrite ( &balance, 4, 1, mfile ); if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); } } } open_month ( file, mnth ) char *file, *mnth; { int x, len, button, do_it, trans_cnt, old_dep_cnt, old_chk_cnt; char a[20], new_mfile[64]; saved = TRUE; old_dep_cnt = num_deps; old_chk_cnt = num_chks; num_chks = num_deps = 0; strcpy ( new_mfile, filename ); strcpy ( &new_mfile[strlen(new_mfile)-4], mnth ); strcpy ( &new_mfile[strlen(new_mfile)], ".DAT" ); if ( ( mfile = fopen ( new_mfile, "br" )) == 0 ) form_alert ( 1, "[1][Can't open the file][CONTINUE]" ); else { do_it = TRUE; fread ( &trans_cnt, 2, 1, mfile ); if ( trans_cnt == 0 ) { button = form_alert ( 1, "[2][The data file for|this month is empty.|Do you want to start|a new month?][YES|NO]" ); if ( button == YES ) { num_trans = load_auto (); } else { do_it = FALSE; num_chks = old_chk_cnt; num_deps = old_dep_cnt; } } else num_trans = trans_cnt; if ( do_it ) { clear_window (); loaded = TRUE; if ( balance < 0 && balance > (-100) ) sprintf ( bal_but, "$-%ld.%02ld", balance/100,labs(balance%100) ); else sprintf ( bal_but, "$%ld.%02ld", balance/100,labs(balance%100) ); strcpy ( monthfile, new_mfile ); strcpy ( acct_name, file ); month = atoi ( mnth ); x = 0; while ( x < trans_cnt ) { read_check ( x, mfile ); if ( strcmp ( checks[x].number, "9999" ) == MATCH ) num_deps += 1; else num_chks += 1; ++x; } if ( x > 0 ) { strcpy ( cur_chk_num, checks[x-1].number ); curchknum = atoi ( cur_chk_num ); if ( strcmp ( cur_chk_num, "9999" ) != MATCH ) { curchknum += 1; sprintf ( a, "%d", curchknum ); len = strlen ( a ); strcpy ( &cur_chk_num[4-len], a ); } } cur_top = edit_top = 0; cur_count = num_trans; cur_chk_strc = checks; strcpy ( windname, acct_name ); strcpy ( &windname[strlen(windname)], ": Edit mode" ); wind_set ( w_h2, WF_NAME, windname, 0, 0 ); full_draw = TRUE; if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OKAY]"); } } } do_arrow () { switch ( msg_buf[4] ) { case WA_UPPAGE: do_uppage (); break; case WA_DNPAGE: do_dnpage (); break; case WA_UPLINE: do_upline (); break; case WA_DNLINE: do_dnline (); break; case WA_LFPAGE: case WA_RTPAGE: do_hslide (); break; } } do_vslide () { GRECT r; int lines_avail; wind_get ( w_h2, WF_VSLIDE, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); if ( r.g_x != msg_buf[4] ) { wind_update ( BEG_UPDATE ); wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); lines_avail = r.g_h / charh; cur_top = (long)msg_buf[4]*((long)cur_count-(long)lines_avail)/1000L; wind_set ( w_h2, WF_VSLIDE, msg_buf[4], 0, 0, 0 ); draw_interior ( r ); wind_update ( END_UPDATE ); } } do_hslide () { GRECT r; wind_get ( w_h2, WF_HSLIDE, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); if ( r.g_x != msg_buf[4] ) { wind_update ( BEG_UPDATE ); wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); left = !left; if ( left ) { wind_set ( w_h2, WF_INFO, infotext, 0, 0 ); wind_set ( w_h2, WF_HSLIDE, 0, 0, 0, 0 ); } else { wind_set ( w_h2, WF_INFO, &infotext[20], 0, 0 ); wind_set ( w_h2, WF_HSLIDE, 166, 0, 0, 0 ); } draw_interior ( r ); wind_update ( END_UPDATE ); } } do_uppage () { GRECT r; int lines_avail; wind_update ( BEG_UPDATE ); wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); lines_avail = r.g_h / charh; cur_top -= lines_avail; if ( cur_top < 0 ) cur_top = 0; wind_update ( END_UPDATE ); draw_interior ( r ); } do_dnpage () { GRECT r; int lines_avail; wind_update ( BEG_UPDATE ); wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); lines_avail = r.g_h / charh; cur_top += lines_avail; if ( cur_top > cur_count - lines_avail ) cur_top = cur_count - lines_avail; draw_interior ( r ); wind_update ( END_UPDATE ); } do_upline () { MFDB s, d; GRECT r; int pxy[8]; if ( cur_top != 0 ) { wind_update ( BEG_UPDATE ); cur_top -= 1; wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); set_clip ( TRUE, r ); graf_mouse ( M_OFF, 0L ); s.fd_addr = 0L; d.fd_addr = 0L; pxy[0] = r.g_x; pxy[1] = r.g_y + 2; pxy[2] = r.g_x + r.g_w; pxy[3] = r.g_y + r.g_h - charh - 2; pxy[4] = r.g_x; pxy[5] = r.g_y + charh + 2; pxy[6] = r.g_x + r.g_w; pxy[7] = r.g_y + r.g_h - 2; vro_cpyfm ( handle, S_ONLY, pxy, &s, &d ); prnt_chk_wnd ( cur_top, r.g_y + charh ); set_clip ( FALSE, r ); calc_vslid ( cur_count ); wind_update ( END_UPDATE ); graf_mouse ( M_ON, 0L ); } } do_dnline () { MFDB s, d; GRECT r; int pxy[8]; int lines_avail, index; wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); lines_avail = r.g_h / charh; if ( (cur_top + lines_avail) < cur_count ) { wind_update ( BEG_UPDATE ); cur_top += 1; index = cur_top + lines_avail - 1; set_clip ( TRUE, r ); graf_mouse ( M_OFF, 0L ); s.fd_addr = 0L; d.fd_addr = 0L; pxy[0] = r.g_x; pxy[1] = r.g_y + charh + 3 - 1*(res==MED); pxy[2] = r.g_x + r.g_w; pxy[3] = r.g_y + r.g_h - 1; pxy[4] = r.g_x; pxy[5] = r.g_y + 3 -1*(res==MED); pxy[6] = r.g_x + r.g_w; pxy[7] = r.g_y + r.g_h - charh - 1; vro_cpyfm ( handle, S_ONLY, pxy, &s, &d ); prnt_chk_wnd ( index, r.g_y + lines_avail * charh ); set_clip ( FALSE, r ); calc_vslid ( cur_count ); wind_update ( END_UPDATE ); graf_mouse ( M_ON, 0L ); } } do_check_canc () { int choice, okay; cancdial_addr[CANCSTRG].ob_spec = canc; choice = get_month (); if ( choice == CANCOK ) { if ( !saved ) { save_month ( monthfile ); clear_window (); } set_canc_menu (); cur_chk_strc = checks; cur_top = 0; open_new_month (); canceling = TRUE; strcpy ( windname, acct_name ); strcpy ( &windname[strlen(windname)], ": Cancel Mode" ); wind_set ( w_h2, WF_NAME, windname, 0, 0 ); } else canceling = FALSE; } clear_cancdial () { int x; for ( x=JAN; x<=MZERO; cancdial_addr[x++].ob_state = NORMAL ) ; if ( month != -1 ) if ( month == 0 ) cancdial_addr[MZERO].ob_state = SELECTED; else cancdial_addr[month+JAN-1].ob_state = SELECTED; } open_new_month () { int mnth, x; for ( x=JAN; x<=MZERO; ++x ) if ( cancdial_addr[x].ob_state == SELECTED ) if ( x == MZERO ) mnth = 0; else mnth = x-JAN+1; sprintf ( cancmnth, "%d", mnth ); open_month ( acct_name, cancmnth ); } do_reconcil () { int choice, okay; int dial_x, dial_y, dial_w, dial_h; if ( !saved ) save_month ( monthfile ); string = get_tedinfo_str ( recndial_addr, ENDBAL ); string[0] = '@'; form_center ( recndial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( recndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); okay = TRUE; do { choice = form_do ( recndial_addr, ENDBAL ); recndial_addr[choice].ob_state = SHADOWED; if ( choice == ENDBOK ) { okay = val_bal (); if ( okay ) rcncl (); } } while ( okay == FALSE && choice == ENDBOK ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } val_bal () { int okay; okay = TRUE; string = get_tedinfo_str ( recndial_addr, ENDBAL ); if ( string[0] == '@' | strlen (string) == 0 ) { form_alert ( 1, "[1][You must provide your|account's ending balance][OK]" ); okay = FALSE; } return ( okay ); } rcncl () { int x, m, chkcnt, depcnt, trans; int dial_x, dial_y, dial_w, dial_h; char s[20]; struct check tmpchk; long endbal, deptot, chktot; chktot = deptot = 0; chkcnt = depcnt = 0; string = get_tedinfo_str ( recndial_addr, ENDBAL ); no_decimal ( string ); endbal = str_to_long ( string ); form_center ( lkmndial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); string = get_tedinfo_str ( lkmndial_addr, SCANMNTH ); strcpy ( string, " " ); objc_draw ( lkmndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); for ( x=0; x<13; ++x ) { strcpy ( s, filename ); sprintf ( &s[strlen(s)-4], "%d", x ); strcpy ( &s[strlen(s)], ".DAT" ); if ( ( mfile = fopen ( s, "br" ) ) == 0 ) form_alert ( 1, "[1][Cannot open file!|Reconciliation abandoned.][OK]" ); else { strcpy ( string, months[x] ); objc_draw ( lkmndial_addr, SCANMNTH, 8, dial_x, dial_y, dial_w, dial_h ); fread ( &trans, 2, 1, mfile ); for ( m=0; m<trans; ++m ) { fread ( tmpchk.number, 1, 4, mfile ); fread ( tmpchk.payee, 1, 30, mfile ); fread ( tmpchk.memo, 1, 30, mfile ); fread ( tmpchk.date, 1, 8, mfile ); fread ( &tmpchk.amount, 4, 1, mfile ); fread ( tmpchk.cancel, 1, 1, mfile ); fread ( future_use, 1, 40, mfile ); if ( tmpchk.cancel[0] == ' ' ) if ( strncmp ( tmpchk.number, "9999", 4 ) == MATCH ) { depcnt += 1; deptot += tmpchk.amount; } else { chkcnt += 1; chktot += tmpchk.amount; } } } if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); } form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); show_report ( endbal, chkcnt, chktot, depcnt, deptot ); } show_report ( endbal, chkcnt, chktot, depcnt, deptot ) long endbal, chktot, deptot; int chkcnt, depcnt; { long balshld, dif, subtot; int dial_x, dial_y, dial_w, dial_h; subtot = endbal - chktot; balshld = subtot + deptot; dif = balshld - balance; string = rprtdial_addr[RECENDB].ob_spec; if ( endbal < 0 && endbal > (-100) ) sprintf ( &string[1], "$-%5ld.%02ld", endbal/100,labs(endbal%100) ); else sprintf ( &string[1], "%6ld.%02ld", endbal/100, labs(endbal%100) ); string = rprtdial_addr[RECOUTCH].ob_spec; sprintf ( &string[22], "%d", chkcnt ); strcpy ( &string[strlen(string)], ")......." ); string = rprtdial_addr[RECCHKS].ob_spec; sprintf ( &string[5], "%6ld.%02ld", chktot/100, chktot%100 ); string = rprtdial_addr[RECSUBT].ob_spec; if ( subtot < 0 && subtot > (-100) ) sprintf ( string, "-%5ld.%02ld", subtot/100, labs(subtot%100) ); else sprintf ( string, "%6ld.%02ld", subtot/100, labs(subtot%100) ); string = rprtdial_addr[RECOUTDP].ob_spec; sprintf ( &string[24], "%d", depcnt ); strcpy ( &string[strlen(string)], ")....." ); string = rprtdial_addr[RECDEPS].ob_spec; sprintf ( &string[5], "%6ld.%02ld", deptot/100, deptot%100 ); string = rprtdial_addr[RECBALSH].ob_spec; if ( balshld < 0 && balshld > (-100) ) sprintf ( string, "-%5ld.%02ld", balshld/100, labs(balshld%100) ); else sprintf ( string, "%6ld.%02ld", balshld/100, labs(balshld%100) ); string = rprtdial_addr[RECBALIS].ob_spec; if ( balance < 0 && balance > (-100) ) sprintf ( string, "-%5ld.%02ld", balance/100, labs(balance%100) ); else sprintf ( string, "%6ld.%02ld", balance/100, labs(balance%100) ); string = rprtdial_addr[RECDIF].ob_spec; if ( dif < 0 && dif > (-100) ) sprintf ( &string[1], "-%5ld.%02ld", dif/100, labs(dif%100) ); else sprintf ( &string[1], "%6ld.%02ld", dif/100, labs(dif%100) ); form_center ( rprtdial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( rprtdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); form_do ( rprtdial_addr, 0 ); rprtdial_addr[RECOK].ob_state = SHADOWED; form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } do_auto () { int choice, len, okay, i; int dial_x, dial_y, dial_w, dial_h; set_auto_chk (); form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); okay = FALSE; do { choice = form_do ( check_addr, DATE ); check_addr[choice].ob_state = SHADOWED; switch ( choice ) { case CHKDONE: case CHKNEXT: okay = validate_check (); if ( okay ) { string = get_tedinfo_str ( check_addr, NUMBER ); if ( strcmp ( string, "0000" ) != MATCH && strcmp ( string, "9999" ) != MATCH ) strcpy ( string, "0000" ); string = get_tedinfo_str ( check_addr, MEMO ); strcpy ( string, "AUTO " ); string = get_tedinfo_str ( check_addr, PAYEE ); for ( i=strlen(string); i<30; string[i++]=' ' ); save_auto (); } if ( choice != CHKDONE | !okay ) { if ( choice == CHKNEXT ) set_auto_chk (); objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); } break; case CHKCANCL: clear_check (); break; } } while ( (choice != CHKDONE | okay == FALSE) && choice != CHKCANCL ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } save_auto () { FILE *autofile; char file[64]; long amount; int choice, old_count, new_count, file_len; strcpy ( file, filename ); strcpy ( &file[strlen(file)-4], ".AUT" ); if ( ( autofile = fopen ( file, "br+" ) ) == NULL ) { choice = form_alert ( 1, "[2][Start a new AUTO file?][YES|NO]" ); if ( choice = YES ) autofile = opn_nw_auto ( file ); } if ( autofile != NULL ) { fread ( &old_count, 2, 1, autofile ); new_count = old_count + 1; rewind ( autofile ); fwrite ( &new_count, 2, 1, autofile ); file_len = old_count * REC_LENGTH; fseek ( autofile, (long) file_len, FROM_CUR_POS ); string = get_tedinfo_str ( check_addr, NUMBER ); fwrite ( string, 1, 4, autofile ); string = get_tedinfo_str ( check_addr, PAYEE ); fwrite ( string, 1, 30, autofile ); fwrite ( "AUTO ", 1, 30, autofile ); string = get_tedinfo_str ( check_addr, DATE ); fwrite ( string, 1, 8, autofile ); string = get_tedinfo_str ( check_addr, AMOUNT ); no_decimal ( string ); amount = str_to_long ( string ); fwrite ( &amount, 4, 1, autofile ); fwrite ( " ", 1, 1, autofile ); fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, autofile ); if ( fclose ( autofile ) == FAILED ) form_alert ( 1, "[1][File close error!][OKAY]"); } } FILE *opn_nw_auto ( file ) char *file; { FILE *autofile; if ( ( autofile = fopen ( file, "bw" ) ) == NULL ) form_alert ( 1, "[1][Can't open new AUTO file!|Function aborted.][OK]" ); else { fwrite ( &zero, 2, 1, mfile ); fclose ( autofile ); autofile = fopen ( file, "br+" ); } return ( autofile ); } set_auto_chk () { set_chk_strings (); check_addr[CHKNEXT].ob_state = SHADOWED; check_addr[CHKNEXT].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT; check_addr[CHKDONE].ob_flags = SELECTABLE | TOUCHEXIT; string = get_tedinfo_str ( check_addr, NUMBER ); strcpy ( string, "0000" ); string = get_tedinfo_str ( check_addr, MEMO ); strcpy ( string, "AUTO" ); } load_auto () { char autoname[64]; FILE *autofile; int x, count; count = 0; strcpy ( autoname, filename ); strcpy ( &autoname[strlen(autoname)-4], ".AUT" ); if ( ( autofile = fopen ( autoname, "br" )) != NULL ) { fread ( &count, 2, 1, autofile ); x = 0; while ( x < count ) { read_check ( x, autofile ); if ( strcmp ( checks[x].number, "9999" ) == MATCH ) { num_deps += 1; balance += checks[x].amount; } else { num_chks += 1; balance -= checks[x].amount; } ++x; } saved = FALSE; if ( fclose ( autofile ) == FAILED ) form_alert ( 1, "[1][Error closing AUTO file!][CONTINUE]" ); } return ( count ); } get_month () { int choice; int dial_x, dial_y, dial_w, dial_h; clear_cancdial (); form_center ( cancdial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( cancdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); choice = form_do ( cancdial_addr, 0 ); cancdial_addr[choice].ob_state = SHADOWED; form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); return ( choice ); } get_new_date () { int choice, okay; int dial_x, dial_y, dial_w, dial_h; string = get_tedinfo_str ( newdate_addr, NWDATE ); string[0] = 0; form_center ( newdate_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( newdate_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); okay = FALSE; do { choice = form_do ( newdate_addr, NWDATE ); newdate_addr[choice].ob_state = SHADOWED; switch ( choice ) { case DATEOK: okay = chk_date (); if ( !okay ) objc_draw ( newdate_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); else { strcpy ( cur_date, string ); format_date ( date_but, cur_date ); updte_buttons (); } break; case DATECANC: string = get_tedinfo_str ( newdate_addr, NWDATE ); string[0] = '@'; } } while ( okay == FALSE && choice != DATECANC ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } chk_date () { int mnth, day, year, okay; char m[3], d[3], y[3]; string = get_tedinfo_str ( newdate_addr, NWDATE ); if ( strlen ( string ) == 6 ) { strncpy ( m, string, 2 ); m[2] = 0; strncpy ( d, &string[2], 2 ); d[2] = 0; strncpy ( y, &string[4], 2 ); mnth = atoi ( m ); day = atoi ( d ); year = atoi ( y ); if ( mnth < 0 | mnth >12 | day < 1 | day > 31 | year < 0 | year > 99 ) { okay = FALSE; } else okay = TRUE; } else okay = FALSE; if ( !okay ) { form_alert ( 1, "[1][Not a valid date!][CONTINUE]" ); string[0] = 0; } return ( okay ); } do_full () { if ( !full ) wind_set ( w_h2, WF_CURRXYWH, fullx, fully, fullw, fullh ); else wind_set ( w_h2, WF_CURRXYWH, fullx, fully, fullw, 316 -162*(res==MED) ); calc_vslid ( cur_count ); full = !full; } do_search () { int choice, okay; int dial_x, dial_y, dial_w, dial_h; set_search_menu (); clear_search (); form_center ( srchdial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); do { objc_draw ( srchdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); choice = form_do ( srchdial_addr, MNTHFROM ); srchdial_addr[choice].ob_state = SHADOWED; switch ( choice ) { case SRCHOK: okay = val_srch (); if ( okay ) search_chks (); break; case SRCHCNCL: search = FALSE; set_menu_entries (); break; } } while ( !okay && choice != SRCHCNCL ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } val_srch () { char f, t; int okay; okay = TRUE; string = get_tedinfo_str ( srchdial_addr, MNTHFROM ); f = string[0]; string = get_tedinfo_str ( srchdial_addr, MNTHTO ); t = string[0]; if ( f < '0' | f > '9' | t < '0' | t > '9' ) { form_alert ( 1, "[1][You must enter a|starting and ending month!][CONTINUE]" ); okay = FALSE; } return ( okay ); } clear_search () { string = get_tedinfo_str ( srchdial_addr, MNTHFROM ); strcpy ( string, "0" ); string = get_tedinfo_str ( srchdial_addr, MNTHTO ); strcpy ( string, "12" ); string = get_tedinfo_str ( srchdial_addr, NUMFROM ); strcpy ( string, "0000" ); string = get_tedinfo_str ( srchdial_addr, NUMTO ); strcpy ( string, "9999" ); string = get_tedinfo_str ( srchdial_addr, AMNTFROM ); strcpy ( string, "0000000" ); string = get_tedinfo_str ( srchdial_addr, AMNTTO ); strcpy ( string, "9999999" ); string = get_tedinfo_str ( srchdial_addr, PAYEFROM ); strcpy ( string, "ANY" ); string = get_tedinfo_str ( srchdial_addr, MEMOFROM ); strcpy ( string, "ANY" ); } search_chks () { GRECT r; int x, count, i, any_payee, any_memo, trans, c_cnt, d_cnt; char s[64], p[31], m[31]; long tot_debit, tot_credit; count = c_cnt = d_cnt = 0; tot_debit = tot_credit = 0; search = TRUE; edit_top = cur_top; cur_chk_strc = srch_checks; any_payee = any_memo = FALSE; srch_trans = 0; get_srch_param (); if ( !saved ) do_save (); for ( x=start_mnth; x<=end_mnth && count < 1000; ++x ) { strcpy ( s, filename ); sprintf ( &s[strlen(s)-4], "%d", x ); strcpy ( &s[strlen(s)], ".DAT" ); if ( ( mfile = fopen ( s, "br" ) ) == 0 ) form_alert ( 1, "[1][Cannot open file!|Search abandoned.][CONTINUE]" ); else { fread ( &trans, 2, 1, mfile ); srch_trans += trans; i = 0; if ( strcmp ( srch_payee, "ANY" ) == MATCH ) any_payee = TRUE; if ( strcmp ( srch_memo, "ANY" ) == MATCH ) any_memo = TRUE; while ( i++ < trans && count < 1000 ) { fread ( srch_checks[count].number, 1, 4, mfile ); fread ( srch_checks[count].payee, 1, 30, mfile ); fread ( srch_checks[count].memo, 1, 30, mfile ); fread ( srch_checks[count].date, 1, 8, mfile ); fread ( &srch_checks[count].amount, 4, 1, mfile ); fread ( srch_checks[count].cancel, 1, 1, mfile ); fread ( future_use, 1, 40, mfile ); strcpy ( p, srch_checks[count].payee ); strcpy ( m, srch_checks[count].memo ); if ( any_payee ) strcpy ( srch_payee, srch_checks[count].payee ); else if ( strlen ( p ) >= strlen ( srch_payee ) ) p[ strlen ( srch_payee ) ] = 0; if ( any_memo ) strcpy ( srch_memo, srch_checks[count].memo ); else if ( strlen ( m ) >= strlen ( srch_memo ) ) m[ strlen ( srch_memo ) ] = 0; make_upper_case ( srch_payee ); make_upper_case ( srch_memo ); make_upper_case ( p ); make_upper_case ( m ); if ( atoi ( srch_checks[count].number ) >= start_num && atoi ( srch_checks[count].number ) <= end_num && srch_checks[count].amount >= start_amnt && srch_checks[count].amount <= end_amnt && ( strcmp ( p, srch_payee ) == MATCH ) && ( strcmp ( m, srch_memo ) == MATCH ) ) { ++count; if ( strcmp ( srch_checks[count-1].number, "9999" ) == MATCH ) { tot_credit += srch_checks[count-1].amount; ++d_cnt; } else { tot_debit += srch_checks[count-1].amount; ++c_cnt; } } } } if ( count == 1000 ) form_alert(1,"[1][You've reached the search|function's 1000 check limit.|All checks that match the|search parameters may not|be shown!][OK]"); if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OKAY]"); } cur_top = 0; cur_count = count; strcpy ( windname, acct_name ); strcpy ( &windname[strlen(windname)], ": Search mode" ); wind_set ( w_h2, WF_NAME, windname, 0, 0 ); full_draw = TRUE; sprintf ( chtot, "%6ld.%02ld", tot_debit/100, tot_debit%100 ); sprintf ( dptot, "%6ld.%02ld", tot_credit/100, tot_credit%100 ); sprintf ( chcnt, "%d", c_cnt ); sprintf ( dpcnt, "%d", d_cnt ); search_report (); } search_report () { int dial_x, dial_y, dial_w, dial_h; string = srtodial_addr[DBCNT].ob_spec; strcpy ( string, chcnt ); string = srtodial_addr[DBTOT].ob_spec; strcpy ( string, chtot ); string = srtodial_addr[CRCNT].ob_spec; strcpy ( string, dpcnt ); string = srtodial_addr[CRTOT].ob_spec; strcpy ( string, dptot ); form_center ( srtodial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( srtodial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); form_do ( srtodial_addr, 0 ); srtodial_addr[SRTOOK].ob_state = SHADOWED; form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } get_srch_param () { char s[10]; string = get_tedinfo_str ( srchdial_addr, MNTHFROM ); start_mnth = atoi ( string ); string = get_tedinfo_str ( srchdial_addr, MNTHTO ); end_mnth = atoi ( string ); string = get_tedinfo_str ( srchdial_addr, NUMFROM ); start_num = atoi ( string ); string = get_tedinfo_str ( srchdial_addr, NUMTO ); end_num = atoi ( string ); string = get_tedinfo_str ( srchdial_addr, AMNTFROM ); no_decimal ( string ); start_amnt = str_to_long ( string ); string = get_tedinfo_str ( srchdial_addr, AMNTTO ); no_decimal ( string ); end_amnt = str_to_long ( string ); srch_payee = get_tedinfo_str ( srchdial_addr, PAYEFROM ); srch_memo = get_tedinfo_str ( srchdial_addr, MEMOFROM ); } set_menu_entries () { menu_ienable ( menu_addr, CLOSEMBR, loaded ); menu_ienable ( menu_addr, OPENMBR, !loaded ); menu_ienable ( menu_addr, NEWACCNT, !loaded ); menu_ienable ( menu_addr, QUIT, TRUE ); menu_ienable ( menu_addr, ENTER, loaded ); menu_ienable ( menu_addr, SEARCH, loaded ); menu_ienable ( menu_addr, CHKCAN, loaded ); menu_ienable ( menu_addr, NEWMNTH, loaded ); menu_ienable ( menu_addr, RECONCIL, loaded ); menu_ienable ( menu_addr, PRNTWIND, loaded ); menu_ienable ( menu_addr, PRNTREG, loaded ); menu_ienable ( menu_addr, NEWYEAR, !loaded ); menu_ienable ( menu_addr, CHKAUTO, loaded ); menu_ienable ( menu_addr, NEWDATE, TRUE ); menu_ienable ( menu_addr, IMPORT, !loaded ); } set_search_menu () { menu_ienable ( menu_addr, CLOSEMBR, TRUE ); menu_ienable ( menu_addr, OPENMBR, FALSE ); menu_ienable ( menu_addr, QUIT, TRUE ); menu_ienable ( menu_addr, NEWACCNT, FALSE ); menu_ienable ( menu_addr, ENTER, FALSE ); menu_ienable ( menu_addr, SEARCH, TRUE ); menu_ienable ( menu_addr, CHKCAN, FALSE ); menu_ienable ( menu_addr, CHKAUTO, FALSE ); menu_ienable ( menu_addr, NEWMNTH, FALSE ); menu_ienable ( menu_addr, RECONCIL, FALSE ); menu_ienable ( menu_addr, PRNTWIND, TRUE ); menu_ienable ( menu_addr, PRNTREG, TRUE ); menu_ienable ( menu_addr, NEWYEAR, FALSE ); menu_ienable ( menu_addr, NEWDATE, TRUE ); } set_canc_menu () { menu_ienable ( menu_addr, CLOSEMBR, TRUE ); menu_ienable ( menu_addr, OPENMBR, FALSE ); menu_ienable ( menu_addr, QUIT, TRUE ); menu_ienable ( menu_addr, NEWACCNT, FALSE ); menu_ienable ( menu_addr, ENTER, FALSE ); menu_ienable ( menu_addr, SEARCH, FALSE ); menu_ienable ( menu_addr, CHKCAN, FALSE ); menu_ienable ( menu_addr, CHKAUTO, FALSE ); menu_ienable ( menu_addr, NEWMNTH, FALSE ); menu_ienable ( menu_addr, RECONCIL, FALSE ); menu_ienable ( menu_addr, PRNTWIND, TRUE ); menu_ienable ( menu_addr, PRNTREG, TRUE ); menu_ienable ( menu_addr, NEWYEAR, FALSE ); menu_ienable ( menu_addr, NEWDATE, TRUE ); } draw_interior ( clip ) GRECT clip; { GRECT r; int lines_avail, lines_shown; graf_mouse ( M_OFF, 0L ); vswr_mode ( handle, MD_REPLACE ); if ( msg_buf[3] == w_h1 ) { if ( res == HIGH ) { r.g_x = 1; r.g_y = 337; r.g_w = 638; r.g_h = 63; } else { r.g_x = 1; r.g_y = 167; r.g_w = 638; r.g_h = 32; } draw_rec ( r, 2, 4, GREEN ); draw_buttons (); } else { if ( !full_draw ) set_clip ( TRUE, clip ); wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); draw_rec ( r, 2, 8, WHITE ); if ( full ) lines_avail = 20; else lines_avail = 15; lines_shown = cur_count - cur_top; if ( lines_avail > lines_shown ) { cur_top = cur_count - lines_avail; if ( cur_top < 0 ) cur_top = 0; } if ( cur_count == 0 ) calc_vslid ( 1 ); else calc_vslid ( cur_count ); calc_hslid ( NUM_COLUMNS ); updte_chk_wind (); full_draw = FALSE; set_clip ( FALSE, clip ); } graf_mouse ( M_ON, 0L ); } updte_chk_wind () { int i, y; wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh ); i = cur_top; y = 0; while ( (i < cur_count) && (i < cur_top + wrkh / charh) ) { prnt_chk_wnd ( i, wrky + charh + y * charh ); ++i; ++y; } } prnt_chk_wnd ( index, row ) int index, row; { char a[40], s[10]; if ( left ) { v_gtext ( handle, 6, row, cur_chk_strc[index].cancel ); v_gtext ( handle, 25, row, cur_chk_strc[index].number ); sprintf ( a, "$%5ld.%02ld", cur_chk_strc[index].amount/100, cur_chk_strc[index].amount%100 ); v_gtext ( handle, 77, row, a ); v_gtext ( handle, 169, row, cur_chk_strc[index].payee ); strcpy ( a, cur_chk_strc[index].memo ); a[24] = 0; v_gtext ( handle, 424, row, a ); } else { v_gtext ( handle, 9, row, cur_chk_strc[index].payee ); v_gtext ( handle, 264, row, cur_chk_strc[index].memo ); strcpy ( s, cur_chk_strc[index].date ); format_date ( a, s ); v_gtext ( handle, 520, row, a ); } } restore_amounts ( num ) int num; { num_trans += 1; if ( strcmp ( checks[num].number, "9999" ) == MATCH ) { num_deps += 1; balance += checks[num].amount; } else { num_chks += 1; balance -= checks[num].amount; } } calc_vslid ( line_cnt ) int line_cnt; { int lines_avail, vslid_siz, pos; if ( line_cnt == 0 ) line_cnt = 1; wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh ); lines_avail = wrkh / charh; vslid_siz = 1000 * lines_avail / line_cnt; wind_set ( w_h2, WF_VSLSIZE, vslid_siz, 0, 0, 0 ); pos = (int) ( (float)(cur_top) ) / ( (float)(line_cnt - lines_avail) ) * 1000; wind_set ( w_h2, WF_VSLIDE, pos, 0, 0, 0 ); } calc_hslid ( col_cnt ) int col_cnt; { int cols_avail, hslid_siz, pos, lft; if ( left ) lft = 0; else lft = 16; wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh ); cols_avail = wrkw / charw; hslid_siz = (int) ((1000L * (long) cols_avail) / (long) col_cnt); wind_set ( w_h2, WF_HSLSIZE, hslid_siz, 0, 0, 0 ); pos = (int) ( (float)(lft) ) / ( (float)(col_cnt - cols_avail) ) * 1000; wind_set ( w_h2, WF_HSLIDE, pos, 0, 0, 0 ); } do_enter () { int choice, okay; int dial_x, dial_y, dial_w, dial_h; set_chk_strings (); check_addr[CHKNEXT].ob_state = SHADOWED; check_addr[CHKNEXT].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT; check_addr[CHKDONE].ob_flags = SELECTABLE | TOUCHEXIT; form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); okay = FALSE; do { choice = form_do ( check_addr, NUMBER ); check_addr[choice].ob_state = SHADOWED; switch ( choice ) { case CHKDONE: case CHKNEXT: okay = validate_check (); if ( okay ) { saved = FALSE; move_check_data ( num_trans ); strcpy ( checks[num_trans].cancel, " " ); updte_amounts ( num_trans ); updte_buttons (); } if ( choice != CHKDONE | !okay ) { if ( choice == CHKNEXT ) set_chk_strings (); objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); } break; case CHKCANCL: clear_check (); break; } } while ( (choice != CHKDONE | okay == FALSE) && choice != CHKCANCL ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); cur_count = num_trans; full_draw = TRUE; } open_acct ( file ) char *file; { int x, len; char zip[10], buf[25]; if ( ( acctfile = fopen ( file, "br" )) == 0 ) form_alert ( 1, "[1][Can't open the file][CONTINUE]" ); else { fread ( chkname, 1, 26, acctfile ); fread ( chkstreet, 1, 26, acctfile ); fread ( chkcity, 1, 16, acctfile ); fread ( buf, 1, 10, acctfile ); strcpy ( &chkcity[strlen(chkcity)], ", " ); fread ( &chkcity[strlen(chkcity)], 1, 3, acctfile ); strcpy ( &chkcity[strlen(chkcity)], " " ); fread ( zip, 1, 10, acctfile ); len = strlen ( chkcity ); if ( strlen ( zip ) > 5 ) { strncpy ( &chkcity[len], zip, 5 ); chkcity[len+5] = 0; strcpy ( &chkcity[strlen(chkcity)], "-" ); strcpy ( &chkcity[strlen(chkcity)], &zip[5] ); } else strcpy ( &chkcity[strlen(chkcity)], zip ); fread ( &balance, 4, 1, acctfile ); if ( fclose ( acctfile ) != 0 ) form_alert ( 1, "[1][File close error!][OKAY]"); check_addr[CHKNAME].ob_spec = chkname; check_addr[CHKSTREE].ob_spec = chkstreet; check_addr[CHKCITY].ob_spec = chkcity; do_new_mnth (); if ( loaded ) set_menu_entries (); else balance = 0; } } edit () { int line, index, x; char s[10], t[10]; line = ( mouse_y - wrky - 4 ) / charh; index = line + cur_top; num_trans -= 1; string = get_tedinfo_str ( check_addr, PAYEE ); strcpy ( string, checks[index].payee ); x = strlen ( string ) - 1; while ( string[x--] == ' ' ); string[x+2] = 0; string = get_tedinfo_str ( check_addr, MEMO ); strcpy ( string, checks[index].memo ); x = strlen ( string ) - 1; while ( string[x--] == ' ' ); string[x+2] = 0; string = get_tedinfo_str ( check_addr, NUMBER ); strcpy ( string, checks[index].number ); if ( strcmp ( string, "9999" ) != MATCH ) { balance += checks[index].amount; num_chks -= 1; } else { balance -= checks[index].amount; num_deps -= 1; } string = get_tedinfo_str ( check_addr, DATE ); strcpy ( string, checks[index].date ); string = get_tedinfo_str ( check_addr, PAID ); strcpy ( string, checks[index].cancel ); sprintf ( s, "%ld.%02ld", checks[index].amount/100, checks[index].amount%100 ); x = 0; while ( s[x] != '.' && x<strlen(s) ) ++x; strcpy ( t, " " ); strncpy ( t, s, x ); t[x] = ' '; strcpy ( &t[5], &s[x+1] ); string = get_tedinfo_str ( check_addr, AMOUNT ); strcpy ( string, t ); edit_check ( index ); } edit_check ( num ) int num; { int okay, choice; int dial_x, dial_y, dial_w, dial_h; check_addr[CHKNEXT].ob_state = DISABLED; check_addr[CHKNEXT].ob_flags = NONE; check_addr[CHKDONE].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT; form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); okay = FALSE; do { choice = form_do ( check_addr, NUMBER ); check_addr[choice].ob_state = SHADOWED; switch ( choice ) { case CHKDONE: okay = validate_check (); if ( okay ) { saved = FALSE; move_check_data ( num ); updte_amounts ( num ); graf_mouse ( M_OFF, 0L ); prnt_chk_wnd ( num, wrky + charh + (num-cur_top) * charh ); updte_buttons (); graf_mouse ( M_ON, 0L ); } else objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); break; case CHKCANCL: restore_amounts ( num ); clear_check (); break; } } while ( (choice != CHKDONE | !okay ) && choice != CHKCANCL ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } draw_rec ( rec, inter, fill, color ) GRECT rec; int inter, fill, color; { int pxy[4]; graf_mouse ( M_OFF, 0L ); vsf_interior ( handle, inter ); vsf_style ( handle, fill ); vsf_color ( handle, color ); pxy[0] = rec.g_x; pxy[1] = rec.g_y; pxy[2] = rec.g_x + rec.g_w - 1; pxy[3] = rec.g_y + rec.g_h - 1; vr_recfl ( handle, pxy ); graf_mouse ( M_ON, 0L ); } set_buttons () { if ( balance < 0 && balance > (-100) ) sprintf ( bal_but, "$-%ld.%02ld", balance/100, labs(balance%100) ); else sprintf ( bal_but, "$%ld.%02ld", balance/100, labs(balance%100) ); sprintf ( trans_but, "%d", num_trans ); sprintf ( check_but, "%d", num_chks ); sprintf ( dep_but, "%d", num_deps ); if ( month == -1 ) strcpy ( mnth_but, "NONE" ); else strcpy ( mnth_but, months[month] ); } set_chk_strings () { string = get_tedinfo_str ( check_addr, NUMBER ); strcpy ( string, cur_chk_num ); string = get_tedinfo_str ( check_addr, DATE ); strcpy ( string, cur_date ); string = get_tedinfo_str ( check_addr, PAYEE ); string[0] = '@'; string = get_tedinfo_str ( check_addr, AMOUNT ); string[0] = '@'; string = get_tedinfo_str ( check_addr, MEMO ); string[0] = '@'; string = get_tedinfo_str ( check_addr, PAID ); string[0] = 0; } clear_newacct () { int x; for ( x=NEWNAME; x<=NEWBALNC; ++x ) { string = get_tedinfo_str ( newacct_addr, x ); string[0] = '@'; } newacct_addr[NEWCANCL].ob_state = SHADOWED; } clear_check () { string = get_tedinfo_str ( check_addr, PAYEE ); string[0] = '@'; string = get_tedinfo_str ( check_addr, AMOUNT ); string[0] = '@'; string = get_tedinfo_str ( check_addr, MEMO ); string[0] = '@'; } do_redraw ( rec1 ) GRECT *rec1; { GRECT rec2; wind_update ( BEG_UPDATE ); wind_get ( msg_buf[3], WF_FIRSTXYWH, &rec2.g_x, &rec2.g_y, &rec2.g_w, &rec2.g_h ); while ( rec2.g_w && rec2.g_h ) { if ( rc_intersect ( rec1, &rec2 ) ) draw_interior ( rec2 ); wind_get ( msg_buf[3], WF_NEXTXYWH, &rec2.g_x, &rec2.g_y, &rec2.g_w, &rec2.g_h ); } wind_update ( END_UPDATE ); } set_clip ( flag, rec ) int flag; GRECT rec; { int pxy[4]; pxy[0] = rec.g_x; pxy[1] = rec.g_y; pxy[2] = rec.g_x + rec.g_w - 1; pxy[3] = rec.g_y + rec.g_h - 1; vs_clip ( handle, flag, pxy ); } open_vwork () { int i; handle = graf_handle ( &charw, &charh, &dum, &dum); for ( i=0; i<10; work_in[i++] = 1 ); work_in[10] = 2; v_opnvwk ( work_in, &handle, work_out ); } draw_buttons() { set_buttons (); button ( "BALANCE", bal_but, 35 ); button ( "# TRANS", trans_but, 131 ); button ( "# CHECKS", check_but, 227 ); button ( "# DEP", dep_but, 323 ); button ( "MONTH", mnth_but, 419 ); button ( "DATE", date_but, 515 ); } button ( str1, str2, x1 ) char *str1, *str2; int x1; { int x2, y1, y2; int pxy[10]; x2 = x1 + 88; y1 = 174 * res; y2 = 198 * res; vswr_mode ( handle, MD_REPLACE ); vsf_color ( handle, WHITE ); pxy[0] = x1; pxy[1] = y1; pxy[2] = x2; pxy[3] = y2; v_bar ( handle, pxy ); pxy[3] = y1; pxy[4] = x2; pxy[5] = y2; pxy[6] = x1; pxy[7] = y2; pxy[8] = x1; pxy[9] = y1; vsl_width ( handle, 3 ); vsl_color ( handle, BLACK ); v_pline ( handle, 5, pxy ); center_butstring ( str1, x1, 184); center_butstring ( str2, x1, 194); } center_butstring ( str, x1, y ) char *str; int x1, y; { int x, x2; x2 = x1 + 88; x = ((x2-x1)-(strlen(str)*8))/2+x1; v_gtext ( handle, x1+5, y * res, " " ); v_gtext ( handle, x, y * res, str ); } get_date () { int date, day, mnth, year; char d[3], m[3], y[4]; date = Tgetdate (); day = date & 0x001f; mnth = (date >> 5) & 0x000f; year = ((date >> 9) & 0x007f) + 80; year = year % 100; sprintf ( d, "%d", day ); sprintf ( m, "%d", mnth ); sprintf ( y, "%d", year ); if ( mnth < 10 ) { date_but[0] = '0'; cur_date[0] = '0'; strcpy ( &date_but[1], m ); strcpy ( &cur_date[1], m ); } else { strcpy ( date_but, m ); strcpy ( cur_date, m ); } date_but[2] = '/'; if ( day < 10 ) { date_but[3] = '0'; cur_date[2] = '0'; strcpy ( &date_but[4], d ); strcpy ( &cur_date[3], d ); } else { strcpy ( &date_but[3], d ); strcpy ( &cur_date[2], d ); } date_but[5] = '/'; if ( year < 10 ) { date_but[6] = '0'; cur_date[4] = '0'; strcpy ( &date_but[7], y ); strcpy ( &cur_date[5], y ); } else { strcpy ( &date_but[6], y ); strcpy ( &cur_date[4], y ); } } char *get_tedinfo_str ( tree, object ) OBJECT *tree; int object; { TEDINFO *ob_tedinfo; ob_tedinfo = (TEDINFO *) tree[object].ob_spec; return ( ob_tedinfo->te_ptext ); } select_file ( path, fnme, deflt, display) char *path, *fnme, *deflt; int display; { int x, choice; char ch; if ( display == FALSE ) for ( x=0; x<20; fnme[x++] = '\0' ); Dgetpath ( path, 0 ); strcpy ( &path[strlen(path)], "\\" ); strcpy ( &path[strlen(path)], deflt ); fsel_input ( path, fnme, &choice ); x = strlen ( path ); while ( ( ch = path[--x] ) != '\\' && x > 0 ); path[x+1] = '\0'; return ( choice ); } write_new_info () { int len, x; char s[10], tmpfile[64]; FILE *f; string = get_tedinfo_str ( newacct_addr, NEWNAME ); fwrite ( string, 1, 26, acctfile ); string = get_tedinfo_str ( newacct_addr, NEWADDR ); fwrite ( string, 1, 26, acctfile ); string = get_tedinfo_str ( newacct_addr, NEWCITY ); fwrite ( string, 1, 26, acctfile ); string = get_tedinfo_str ( newacct_addr, NEWSTATE ); fwrite ( string, 1, 3, acctfile ); string = get_tedinfo_str ( newacct_addr, NEWZIP ); fwrite ( string, 1, 10, acctfile ); string = get_tedinfo_str ( newacct_addr, NEWBALNC ); no_decimal ( string ); balance = str_to_long ( string ); fwrite ( &balance, 1, 4, acctfile ); if ( fclose ( acctfile ) != 0 ) form_alert ( 1, "[1][File close error!][OKAY]"); for ( x=0; x<13; ++x ) { sprintf ( s, "%d", x ); strcpy ( &s[strlen(s)], ".dat" ); ob_tedinfo = (TEDINFO *) newfile_addr[FILENAME].ob_spec; tmpfile[0] = Dgetdrv () + 'a'; strcpy ( &tmpfile[1], ":" ); Dgetpath ( &tmpfile[strlen(tmpfile)], DFLT_DRV ); strcpy ( &tmpfile[strlen(tmpfile)], "\\" ); strcpy ( &tmpfile[strlen(tmpfile)], ob_tedinfo->te_ptext ); strcpy ( &tmpfile[strlen(tmpfile)], s ); if ( ( f = fopen ( tmpfile, "bw" ) ) == NULL ) form_alert ( 1, "[1][Error creating file!][OK]" ); else fwrite ( &zero, 2, 1, f ); if ( fclose ( f ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); } } validate_check () { int okay, len; char a, d; okay = FALSE; if ( num_trans == 500 ) form_alert(1,"[1][This month cannot hold |any more transactions. | |The maximum number of |transactions is 500.][OK]"); else { string = get_tedinfo_str ( check_addr, AMOUNT ); a = string[0]; string = get_tedinfo_str ( check_addr, DATE ); len = strlen ( string ); d = string[0]; if ( a == '@' ) form_alert ( 1, "[1][You must fill in|an amount!][Okay]" ); else if ( len < 6 | d == '@' ) form_alert ( 1, "[1][You must complete|the date field!][OKAY]" ); else okay = TRUE; } return ( okay ); } move_check_data ( number ) int number; { int len; long amount; char t[10], a, d; string = get_tedinfo_str ( check_addr, AMOUNT ); no_decimal ( string ); amount = str_to_long ( string ); checks[number].amount = amount; string[0] = '@'; string = get_tedinfo_str ( check_addr, PAYEE ); strcpy ( checks[number].payee, string ); if ( checks[number].payee[0] == '@' ) strcpy ( checks[number].payee, spaces ); else { len = strlen ( checks[number].payee ); strcpy ( &checks[number].payee[len], &spaces[len] ); } string[0] = '@'; string = get_tedinfo_str ( check_addr, MEMO ); strcpy ( checks[number].memo, string ); if ( checks[number].memo[0] == '@' ) strcpy ( checks[number].memo, spaces ); else { len = strlen ( checks[number].memo ); strcpy ( &checks[number].memo[len], &spaces[len] ); } string[0] = '@'; string = get_tedinfo_str ( check_addr, DATE ); strcpy ( checks[number].date, string ); strcpy ( cur_date, string ); string = get_tedinfo_str ( check_addr, NUMBER ); len = strlen ( string ); if ( len == 4 ) strcpy ( cur_chk_num, string ); else { strcpy ( cur_chk_num, "0000" ); strcpy ( &cur_chk_num[4-len], string ); } strcpy ( checks[number].number, cur_chk_num ); curchknum = atoi ( cur_chk_num ); } updte_amounts ( num ) int num; { char t[20]; int len; if ( strcmp ( checks[num].number, "9999" ) == MATCH ) { strcpy ( checks[num].payee, "DEPOSIT " ); balance += checks[num].amount; num_deps += 1; } else { num_chks += 1; curchknum += 1; sprintf ( t, "%d", curchknum ); len = strlen ( t ); strcpy ( &cur_chk_num[4-len], t ); balance -= checks[num].amount; } num_trans += 1; cur_count = num_trans; } updte_buttons () { if ( !full ) { set_buttons (); center_butstring ( bal_but, 35, 194 ); center_butstring ( trans_but, 131, 194 ); center_butstring ( check_but, 227, 194 ); center_butstring ( dep_but, 323, 194 ); center_butstring ( mnth_but, 419, 194 ); center_butstring ( date_but, 515, 194 ); } } do_newacct () { int choice, okay; int dial_x, dial_y, dial_w, dial_h; clear_newacct (); form_center ( newacct_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( newacct_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); do { choice = form_do ( newacct_addr, NEWNAME ); newacct_addr[choice].ob_state = SHADOWED; switch ( choice ) { case NEWOK: okay = check_newacct (); if ( !okay ) objc_draw ( newacct_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); else newacct_file (); break; case NEWCANCL: clear_newacct (); } } while ( okay == FALSE && choice != NEWCANCL ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } check_newacct () { int x, okay; okay = TRUE; for ( x=NEWNAME; x<=NEWBALNC; ++x ) { string = get_tedinfo_str ( newacct_addr, x ); if ( string[0] == '@' ) okay = FALSE; } if ( !okay ) form_alert(1,"[1][You must complete|the form to start|a new account!][OK]"); return ( okay ); } newacct_file () { int choice, okay, x; int dial_x, dial_y, dial_w, dial_h; string = get_tedinfo_str ( newfile_addr, FILENAME ); string[0] = 0; for ( x=0; x<64; filename[x++]=0 ); newfile_addr[NEWOK].ob_state = SHADOWED; form_center ( newfile_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); objc_draw ( newfile_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); do { choice = form_do ( newfile_addr, FILENAME ); newfile_addr[choice].ob_state = SHADOWED; switch ( choice ) { case FILEOK: okay = check_file (); if ( !okay ) objc_draw ( newfile_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); else { string = get_tedinfo_str ( newfile_addr, FILENAME ); strcpy ( acct_name, string ); filename[0] = Dgetdrv () + 'a'; filename[1] = ':'; Dgetpath ( &filename[2], DFLT_DRV ); filename[strlen(filename)] = '\\'; strcpy ( &filename[strlen(filename)], string ); strcpy ( &filename[strlen(filename)], ".MCK" ); acctfile = fopen ( filename, "bw" ); if ( acctfile != 0 ) { write_new_info (); open_acct ( filename ); } } break; case FILECANC: string = get_tedinfo_str ( newfile_addr, FILENAME ); string[0] = 0; } } while ( !okay && choice != FILECANC ); form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); } check_file () { int okay; okay = TRUE; string = get_tedinfo_str ( newfile_addr, FILENAME ); if ( strlen ( string ) == 0 ) { form_alert(1,"[1][Invalid filename!][OK]"); okay = FALSE; } return ( okay ); } do_quit () { int button; button = form_alert(1,"[2][Are you sure you|want to quit?][YES|NO]"); if ( button == YES ) { search = FALSE; all_done = TRUE; if ( !saved ) do_save (); } } get_acct () { char path[64]; int button; button = select_file ( path, acct_name, "*.MCK", FALSE ); if ( strlen (acct_name) == 0 ) button = 0; if ( button ) { strcpy ( filename, path ); strcpy ( &filename[strlen(filename)], acct_name ); acct_name[ strlen(acct_name) - 4 ] = 0; } return ( button ); } do_import () { int button, x, i, cnt, choice; char infile[64], outfile[64], s[10]; char *string; FILE *file1, *file2; button = form_alert(1,"[2][The ported 8-bit MicroCheck|files must be in the same|directory from which you|loaded this program.|Are you ready?][YES|NO]"); if ( button == YES ) { choice = get_acct (); if ( choice ) { for ( x=0; x<13; ++x ) { sprintf ( s, "%d", x ); strcpy ( &s[strlen(s)], ".DAT" ); strcpy ( infile, filename ); strcpy ( outfile, infile ); strcpy ( &infile[strlen(infile)-4], s ); if ( x > 9 ) sprintf ( s, "%d", x ); else { s[0] = '0'; sprintf ( &s[1], "%d", x ); } strcpy ( &s[strlen(s)], ".dat" ); for ( i=strlen(outfile)-1; i>0 && outfile[i] != '\\'; --i ); strcpy ( &outfile[i+1], "MONTH" ); strcpy ( &outfile[strlen(outfile)], s ); if ( ( file1 = fopen ( infile, "bw" ) ) == NULL ) form_alert ( 1, "[1][Error creating file!][OK]" ); else if ( ( file2 = fopen ( outfile, "br" ) ) == NULL ) { fwrite ( &zero, 2, 1, file1 ); if ( fclose ( file1 ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); } else { cnt = read_old_checks ( file2 ); fwrite ( &cnt, 2, 1, file1 ); for ( i=0; i<cnt; ++i ) save_check ( i, file1 ); fclose ( file1 ); } } } } } read_old_checks ( f ) FILE *f; { int cnt, i; char test[4], s[10], s2[30]; cnt = 0; fread ( test, 1, 3, f ); test[3] = 0; while ( strcmp ( test, "END" ) != MATCH ) { checks[cnt].cancel[0] = test[0]; checks[cnt].cancel[1] = 0; strcpy ( checks[cnt].number, &test[1] ); fread ( &checks[cnt].number[2], 1, 2, f ); checks[cnt].number[4] = 0; if ( strcmp ( checks[cnt].number, "DEP " ) == MATCH ) strcpy ( checks[cnt].number, "9999" ); else if ( strcmp ( checks[cnt].number, "AUTO" ) == MATCH ) { strcpy ( checks[cnt].number, "0000" ); strcpy ( checks[cnt].memo, "AUTO " ); } fread ( s, 1, 8, f ); strcpy ( checks[cnt].date, s ); strcpy ( &checks[cnt].date[2], &s[3] ); strcpy ( &checks[cnt].date[4], &s[6] ); fread ( checks[cnt].payee, 1, 21, f ); strcpy ( &checks[cnt].payee[21], " " ); checks[cnt].payee[30] = 0; fread ( s, 1, 7, f ); s[7] = 0; for ( i=0; i<7 && s[i] != '.'; ++i ); strcpy ( s2, s ); strcpy ( &s2[i], " " ); strcpy ( &s2[5], &s[i+1] ); no_decimal ( s2 ); checks[cnt].amount = str_to_long ( s2 ); fread ( s2, 1, 22, f ); if ( strcmp ( checks[cnt].memo, "AUTO " ) != MATCH ) { strcpy ( checks[cnt].memo, s2 ); strcpy ( &checks[cnt].memo[22], " " ); } ++cnt; fread ( test, 1, 1, f ); fread ( test, 1, 3, f ); } return ( cnt ); } save_check ( i, f ) int i; FILE *f; { fwrite ( checks[i].number, 1, 4, f ); fwrite ( checks[i].payee, 1, 30, f ); fwrite ( checks[i].memo, 1, 30, f ); fwrite ( checks[i].date, 1, 8, f ); fwrite ( &checks[i].amount, 4, 1, f ); fwrite ( checks[i].cancel, 1, 1, f ); fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, f ); } read_check ( i, f ) int i; FILE f; { fread ( checks[i].number, 1, 4, f ); fread ( checks[i].payee, 1, 30, f ); fread ( checks[i].memo, 1, 30, f ); fread ( checks[i].date, 1, 8, f ); fread ( &checks[i].amount, 4, 1, f ); fread ( checks[i].cancel, 1, 1, f ); fread ( future_use, 1, 40, f ); } clear_window () { GRECT r; wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h ); draw_rec ( r, 2, 8, WHITE ); } print_wind () { int x, c, sp, lines, page, i, stop, key, key_stat, c_cnt, d_cnt; char s[10], amnt[10], date1[10], date2[10], acct[64]; long c_tot, d_tot; stop = FALSE; c_cnt = d_cnt = 0; c_tot = d_tot = 0.00; if ( !Cprnos () ) form_alert ( 1, "[1][Printer not ready!][OK]"); else { page = 1; strcpy ( acct, filename ); acct[strlen(acct)-4] = 0; lines = top_of_page ( page, acct, TRUE ); Cprnout ( '\r' ); Cprnout ( '\n' ); lines += 1; x = 0; while ( x<cur_count && !stop ) { if ( strcmp ( cur_chk_strc[x].cancel, "*" ) == MATCH ) Cprnout ( '*' ); else Cprnout ( ' ' ); Cprnout ( ' ' ); for ( c=0; c<4; Cprnout ( cur_chk_strc[x].number[c++] ) ); Cprnout ( ' ' ); amnt[0]='$'; sprintf ( s, "%ld.%02ld", cur_chk_strc[x].amount/100, cur_chk_strc[x].amount%100 ); sp = 8 - strlen ( s ); for ( c=0; c<sp; amnt[1+c++] = ' ' ); strcpy ( &amnt[sp+1], s ); for ( c=0; c<9; Cprnout ( amnt[c++] ) ); Cprnout ( ' ' ); for ( c=0; c<26; Cprnout ( cur_chk_strc[x].payee[c++] ) ); Cprnout ( ' ' ); for ( c=0; c<26; Cprnout ( cur_chk_strc[x].memo[c++] ) ); Cprnout ( ' ' ); strcpy ( date2, cur_chk_strc[x].date ); format_date ( date1, date2 ); for ( c=0; c<8; Cprnout ( date1[c++] ) ); Cprnout ( '\r' ); Cprnout ( '\n' ); lines += 1; if ( lines > 61 ) { page += 1; lines = top_of_page ( page, acct, FALSE ); } if ( strcmp ( cur_chk_strc[x].number, "9999" ) == MATCH ) { ++d_cnt; d_tot += cur_chk_strc[x].amount; } else { ++c_cnt; c_tot += cur_chk_strc[x].amount; } ++x; if ( ( key_stat = Bconstat ( CONSOLE ) ) == CHAR_AVAIL ) if ( ( key = Bconin ( CONSOLE ) ) == ESCAPE ) stop = TRUE; } if ( lines > 59 ) { page += 1; lines = top_of_page ( page, acct, FALSE ); } print_totals ( c_cnt, d_cnt, c_tot, d_tot ); Cprnout ( '\f' ); } } print_reg () { char mfilename[64], check[85], amnt_str[10], acct[64], num[10]; int len, m, numtrans, c, i, al, lines, page, stop, key, key_stat, c_cnt, d_cnt; long amnt, c_tot, d_tot; if ( !saved ) save_month ( monthfile ); stop = FALSE; if ( !Cprnos () ) form_alert ( 1, "[1][Printer not ready!][OK]"); else { page = 1; c_cnt = d_cnt = 0; c_tot = d_tot = 0; for ( c=0; c<80; check[c++]=' ' ); check[7] = '$'; check[73] = '/'; check[76] = '/'; check[79] = 0; strcpy ( mfilename, filename ); mfilename[strlen(mfilename)-4] = 0; strcpy ( acct, mfilename ); len = strlen ( mfilename ); lines = top_of_page ( page, acct, TRUE ); m = 0; while ( m<13 && !stop ) { sprintf ( &mfilename[len], "%d", m ); strcpy ( &mfilename[strlen(mfilename)], ".DAT" ); if ( ( mfile = fopen ( mfilename, "br" )) == 0 ) form_alert ( 1, "[1][Can't open the file][CONTINUE]" ); else { fread ( &numtrans, 2, 1, mfile ); if ( numtrans > 0 ) { if ( lines > 59 ) { page += 1; lines = top_of_page ( page, acct, FALSE ); } Cprnout ( '\n' ); for ( i=0; i<strlen(months[m]); Cprnout(months[m][i++]) ); Cprnout ( '\r' ); Cprnout ( '\n' ); for ( i=0; i<78; Cprnout ( rule[i++] ) ); Cprnout ( '\r' ); Cprnout ( '\n' ); lines += 3; } c = 0; while ( c<numtrans && !stop ) { fread ( &check[2], 1, 4, mfile ); strncpy ( num, &check[2], 4 ); num[4] = 0; fread ( &check[17], 1, 25, mfile ); fread ( future_use, 1, 5, mfile ); fread ( &check[44], 1, 25, mfile ); fread ( future_use, 1, 5, mfile ); fread ( &check[71], 1, 2, mfile ); fread ( &check[74], 1, 2, mfile ); fread ( &check[77], 1, 2, mfile ); fread ( future_use, 1, 2, mfile ); fread ( &amnt, 4, 1, mfile ); sprintf ( amnt_str, "%ld.%02ld", amnt/100, amnt%100 ); al = strlen ( amnt_str ); for ( i=8; i<16-al; check[i++]=' ' ); for ( i=0; i<al; ++i ) check[16-al+i] = amnt_str[i]; fread ( &check[0], 1, 1, mfile ); fread ( future_use, 1, 40, mfile ); for ( i=0; i<79; Cprnout ( check[i++] ) ); Cprnout ( '\r' ); Cprnout ( '\n' ); lines += 1; if ( strcmp ( num, "9999" ) == MATCH ) { ++d_cnt; d_tot += amnt; } else { ++c_cnt; c_tot += amnt; } if ( lines > 62 ) { page += 1; lines = top_of_page ( page, acct, FALSE ); } if ( ( key_stat = Bconstat ( CONSOLE ) ) == CHAR_AVAIL ) if ( ( key = Bconin ( CONSOLE ) ) == ESCAPE ) stop = TRUE; ++c; } } fclose ( mfile ); ++m; } if ( lines > 59 ) { page += 1; lines = top_of_page ( page, acct, FALSE ); } print_totals ( c_cnt, d_cnt, c_tot, d_tot ); Cprnout ( '\f' ); } } print_totals ( c_cnt, d_cnt, c_tot, d_tot ) int c_cnt, d_cnt; long c_tot, d_tot; { int i; char s[20]; Cprnout ( '\r' ); Cprnout ( '\n' ); for ( i=0; i<15; Cprnout ( ' ' ), ++i ); strcpy ( s, "# of debits: " ); for ( i=0; i<13; Cprnout ( s[i++] ) ); sprintf ( s, "%d", c_cnt ); for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) ); for ( i=0; i<5; Cprnout ( ' ' ), ++i ); strcpy ( s, "Total: $" ); for ( i=0; i<8; Cprnout ( s[i++] ) ); sprintf ( s, "%ld.%02ld", c_tot/100, c_tot%100 ); for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) ); Cprnout ( '\r' ); Cprnout ( '\n' ); for ( i=0; i<15; Cprnout ( ' ' ), ++i ); strcpy ( s, "# of credits: " ); for ( i=0; i<14; Cprnout ( s[i++] ) ); sprintf ( s, "%d", d_cnt ); for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) ); for ( i=0; i<5; Cprnout ( ' ' ), ++i ); strcpy ( s, "Total: $" ); for ( i=0; i<8; Cprnout ( s[i++] ) ); sprintf ( s, "%ld.%02ld", d_tot/100, d_tot%100 ); for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) ); } format_date ( d1, d2 ) char *d1, *d2; { strcpy ( d1, d2 ); d1[2] = '/'; strcpy ( &d1[3], &d2[2] ); d1[5] = '/'; strcpy ( &d1[6], &d2[4] ); } top_of_page ( page, acct, first_page ) int page, first_page; char *acct; { int i, len; char heading[80]; if ( !first_page ) Cprnout ( '\f' ); Cprnout ( '\n' ); Cprnout ( '\n' ); for ( i=0; i<78; Cprnout( rule[i++]) ); Cprnout ( '\r' ); Cprnout ( '\n' ); strcpy ( heading, "ACCOUNT: " ); strcpy ( &heading[9], acct ); heading[strlen(heading)] = ' '; strcpy ( &heading[33], "DATE: " ); strcpy ( &heading[39], date_but ); heading[47] = ' '; strcpy ( &heading[68], "PAGE: " ); sprintf ( &heading[74], "%d", page ); len = strlen (heading); for ( i=0; i<len; Cprnout(heading[i++]) ); Cprnout ( '\r' ); Cprnout ( '\n' ); for ( i=0; i<78; Cprnout(rule[i++]) ); Cprnout ( '\r' ); Cprnout ( '\n' ); Cprnout ( '\n' ); return ( 6 ); } do_new_year () { int choice, x, m, trans, cnt; int dial_x, dial_y, dial_w, dial_h; char s[64], mnth0[64]; FILE *tfile; struct check tmpchk; choice = form_alert(2,"[2][WARNING! This function will|destroy existing MicroCheck|files!| |Do you want to continue?][YES|NO]"); if ( choice == YES ) { choice = form_alert(2,"[2][Are you absolutely sure that|you want to begin a new year?| ][YES|NO]"); if ( choice == YES ) { cnt = 0; choice = get_acct (); if ( choice ) { if ( ( tfile = fopen ( "TEMP.DAT", "bw" ) ) == 0 ) form_alert ( 1, "[1][Cannot open file!|New Year abandoned.][OK]" ); else { fwrite ( &cnt, 2, 1, tfile ); form_center ( lkmndial_addr, &dial_x, &dial_y, &dial_w, &dial_h ); form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h ); string = get_tedinfo_str ( lkmndial_addr, SCANMNTH ); strcpy ( string, " " ); objc_draw ( lkmndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h ); for ( x=0; x<13; ++x ) { strcpy ( s, filename ); sprintf ( &s[strlen(s)-4], "%d", x ); strcpy ( &s[strlen(s)], ".DAT" ); if ( x==0 ) strcpy ( mnth0, s ); if ( ( mfile = fopen ( s, "br" ) ) == 0 ) form_alert ( 1, "[1][Cannot open monthly files!|New Year abandoned.][OK]" ); else { strcpy ( string, months[x] ); objc_draw ( lkmndial_addr, SCANMNTH, 8, dial_x, dial_y, dial_w, dial_h ); fread ( &trans, 2, 1, mfile ); for ( m=0; m<trans; ++m ) { fread ( tmpchk.number, 1, 4, mfile ); fread ( tmpchk.payee, 1, 30, mfile ); fread ( tmpchk.memo, 1, 30, mfile ); fread ( tmpchk.date, 1, 8, mfile ); fread ( &tmpchk.amount, 4, 1, mfile ); fread ( tmpchk.cancel, 1, 1, mfile ); fread ( future_use, 1, 40, mfile ); if ( tmpchk.cancel[0] == ' ' ) { fwrite ( tmpchk.number, 1, 4, tfile ); fwrite ( tmpchk.payee, 1, 30, tfile ); fwrite ( tmpchk.memo, 1, 30, tfile ); fwrite ( tmpchk.date, 1, 8, tfile ); fwrite ( &tmpchk.amount, 4, 1, tfile ); fwrite ( tmpchk.cancel, 1, 1, tfile ); fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, tfile ); cnt += 1; } } if ( fclose ( mfile ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); mfile = fopen ( s, "bw" ); fwrite ( &zero, 2, 1, mfile ); fclose ( mfile ); } } rewind ( tfile ); fwrite ( &cnt, 2, 1, tfile ); if ( fclose ( tfile ) != 0 ) form_alert ( 1, "[1][File close error!][OK]"); Fdelete ( mnth0 ); Frename ( zero, "TEMP.DAT", mnth0 ); } } } } } make_upper_case ( string ) char *string; { int x; for ( x=0; x<strlen(string); ++x ) string[x] = toupper ( string[x] ); } no_decimal ( s ) char *s; { int x, i, d, len; char s2[20], s3[20]; strcpy ( s2, s ); len = strlen ( s2 ); i = 0; d = FALSE; for ( x=0; x<len; ++x ) if ( d && s2[x] != ' ' ) ++i; else if ( s2[x] == ' ' ) d = TRUE; if ( i == 0 && len < 6 ) strcpy ( &s2[len], "00" ); else if ( i == 1 || len == 6 ) strcpy ( &s2[len], "0" ); i = 0; for ( x=0; x<strlen(s2); ++x ) if ( s2[x] != ' ' & s2[x] != '.' ) s3[i++] = s2[x]; s3[i] = 0; strcpy ( s, s3 ); } long str_to_long ( s ) char *s; { int x, len, factor; long num; num = 0; len = strlen ( s ); factor = len - 1; for ( x=0; x<len; ++x ) num += (long) ( s[x] - '0' ) * pwrs[factor--]; return ( num ); }